home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12885 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  66 lines

  1. Path: cls.net!news
  2. From: damian@sup.de (Damian Gruszka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: help with strcmp
  5. Date: 3 Apr 1996 10:57:59 GMT
  6. Organization: sup.de
  7. Message-ID: <4jtljo$k33@freeside.cls.de>
  8. References: <4jpiek$lp6@blaze.cs.jhu.edu>
  9. NNTP-Posting-Host: kldos3.sup.de
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. In article <4jpiek$lp6@blaze.cs.jhu.edu>, lasher@hops.cs.jhu.edu says...
  14. >
  15. >For some reason when I try to compare the strings in the following 
  16. >snippet I consistently get a core dump (running on a UNIX machine running 
  17. >Solaris).  Could anyone point out what may be going wrong?  I have run it 
  18. >through the debugger and that was no help at all for me.  here is the 
  19. >code snippet:
  20. >
  21. >#include <stdio.h>
  22. >#include <stdlib.h>
  23. >#include <string.h>
  24. >
  25. >void setup(FILE *);
  26. >
  27. >void main(int argc, char *argv[])
  28. >{
  29. >char            buf[20], data[40], *buff, *arg, *fp;
  30. >FILE            *handle, *dest;
  31. >int             n;
  32. >
  33. >handle = fopen(argv[1], "r");
  34. >if(dest = fopen( "dbuild.out", "w")) setup(dest);
  35. >
  36. >while(!feof(handle)) {
  37. >        n = 0;
  38. >        fp = fgets(data, 40, handle);
  39. >        if ( strcasecmp(fp, "<action>\n") == 0)  /* the coredump is here 
  40. */
  41. >                parseAction(handle, dest); 
  42. >        else if ( strcasecmp(fp, "<control>\n") == 0)
  43. >                parseControl(handle, dest);
  44. >        else if ( strcasecmp(fp, "<general>\n") == 0)
  45. >                parseGeneral(handle, dest); 
  46. >        printf("%s", data);
  47. >        }
  48. >fclose(dest);
  49. >
  50. >}
  51. >
  52. >
  53. >--
  54. >John Davis
  55. >lasher@hops.cs.jhu.edu
  56. >http://hops.cs.jhu.edu/~lasher
  57. >
  58. >UNIX is a very user-friendly operating system 
  59. > it's just picky about who it's friends with.
  60. You can also test fp against NULL.fgets can return NULL and than
  61. the EOF or Error flag will be set.
  62.  
  63. damian
  64. damian@sup.de
  65.  
  66.